<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE html>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="from"%>
<html>
<head>
    <meta charset="UTF-8">
    <title><spring:message code="field_design_platform_name"/></title>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/style/icon.css">
    <script type="text/javascript" src="<%=request.getContextPath() %>/resources/easyui/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/resources/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/treegrid-dnd.js"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/resources/style/main.css">
</head>
<body class="easyui-layout">
<script type="text/javascript">

    var fieldTreeData = <%=request.getAttribute("fieldData") %>;
    var fieldCatalogType="<spring:message code="field_catalog_type"/>";
    var fieldFloat="<spring:message code="field_data_float_type"/>"
    var fieldText="<spring:message code="field_data_text_type"/>";
    var fieldPicture="<spring:message code="field_data_picture_type"/>";
    var fieldAttach="<spring:message code="field_data_attach_type"/>";
    var fieldMatrix="<spring:message code="field_data_matrix_type"/>";
    var fieldMulti="<spring:message code="field_data_multi_type"/>";
    var field3D="<spring:message code="field_data_3D_type"/>";
    var fieldLink="<spring:message code="field_data_link_type"/>";
    var fieldTime="<spring:message code="field_data_time_type"/>";
    var fieldVideo="<spring:message code="field_data_video_type"/>";
    var field3Matrix="<spring:message code="field_data_3matrix_type"/>";
    
    var fieldCatalogIcon="<spring:message code="field_catalog_icon"/>";
    var fieldFloatIcon="<spring:message code="field_float_icon"/>"
    var fieldTextIcon="<spring:message code="field_text_icon"/>";
    var fieldPictureIcon="<spring:message code="field_picture_icon"/>";
    var fieldAttachIcon="<spring:message code="field_attach_icon"/>";
    var fieldMatrixIcon="<spring:message code="field_matrix_icon"/>";
    var fieldMultiIcon="<spring:message code="field_multi_icon"/>";
    var field3DIcon="<spring:message code="field_3D_icon"/>";
    var fieldLinkIcon="<spring:message code="field_link_icon"/>";
    var fieldTimeIcon="<spring:message code="field_time_icon"/>";
    var fieldVideoIcon="<spring:message code="field_video_icon"/>";
    var fieldDataIcon="<spring:message code="field_data_icon"/>";
    
    var fieldCatalogName="<spring:message code="field_catalog_name"/>";
    var fieldFloatName="<spring:message code="field_data_float_name"/>"
    var fieldTextName="<spring:message code="field_data_text_name"/>";
    var fieldPictureName="<spring:message code="field_data_picture_name"/>";
    var fieldAttachName="<spring:message code="field_data_attach_name"/>";
    var fieldMatrixName="<spring:message code="field_data_matrix_name"/>";
    var fieldMultiName="<spring:message code="field_data_multi_name"/>";
    var field3DName="<spring:message code="field_data_3D_name"/>";
    var fieldLinkName="<spring:message code="field_data_link_name"/>";
    var fieldTimeName="<spring:message code="field_data_time_name"/>";
    var fieldVideoName="<spring:message code="field_data_video_name"/>";
    var field3MatrixName="<spring:message code="field_data_3matrix_name"/>";
    
    var schemaDatabaseName="<spring:message code="schema_database_name"/> ";
    var chooseNode="<spring:message code="tips_two"/> ";
    var notLeaf="<spring:message code="tips_one"/> ";
    var infoNotAll="<spring:message code="tips_info_not_all"/> ";
    var operateTip="<spring:message code="operation_tips"/> ";
    var notMove="<spring:message code="tips_not_move"/> ";
    var fieldDeleteTips="<spring:message code="field_delete_tips"/>";
    var fieldRootId="<spring:message code="field_root_node_id"/>";

    var fieldUrl={
        upload:"<%=request.getContextPath()%>/field/upload",
        download:"<%=request.getContextPath()%>/field/download",
        create:"<%=request.getContextPath()%>/field/create",
        create3Matrix:"<%=request.getContextPath()%>/field/create3Matrix",
        edit:"<%=request.getContextPath()%>/field/edit",
        destroy:"<%=request.getContextPath()%>/field/destroy",
        getRemark1:"<%=request.getContextPath()%>/field/getRemark1",
        getRemark3:"<%=request.getContextPath()%>/field/getRemark3",
        get3MatrixInfo:"<%=request.getContextPath()%>/field/get3MatrixInfo",
        downloadData:"<%=request.getContextPath()%>/field/download",
        moveNode:"<%=request.getContextPath()%>/field/moveNode",
        setDatabase:'<%=request.getContextPath() %>/schema/setDatabase'
    }
    $("#database_data").treegrid({
                data: fieldTreeData
            }
    )
    var params=getFieldReady();
</script>
<div style="margin:5px 0 10px 0;">
</div>
<div class="easyui-tabs" style="width:1000px;height:550px">
    <div title=<spring:message code="field_tab0_title"/> data-options="iconCls:'icon-edit'" style="width:100%;height:100px;padding:10px;">
        <div id="database_info_div" class="easyui-panel" title="<spring:message code="field_info_describe"/>" style="width:500px;height:300px;padding:10px;"
        data-options="
        tools:[{
        iconCls:'icon-save',
        handler:function(){
            infoSave();
        }
        }]
        ">
            <textarea id="info_area" rows="15" cols="64"></textarea>
        </div>
        <div>
            <input type="file" id="uploadPicture" name="file" hidden="hidden" accept=".gif,.jpe,.jpeg,.jpg,.png" onchange="uploadInfoPicture()"/>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" plain="true" onclick="saveInfoPicture()"><spring:message code="info_picture_upload"/></a>
            <input class="easyui-textbox" style="width:350px" id="infoPicName" readonly="readonly">
        </div>
    </div>
    <div title=<spring:message code="field_tabl_title"/> data-options="iconCls:'icon-ok',href:''" style="padding:10px;" selected="true">
        <table title=<spring:message code="field_tab1_table_title"/> id="database_data" class="easyui-treegrid"
               data-options="idField:'id',treeField:'text'"
               animate="false" rownumbers="true">
            <div id="databaseData_dg_toolbar">
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newFieldData()"><spring:message code="field_add"/></a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editFieldData()"><spring:message code="field_edit"/></a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" plain="true" onclick="deleteFieldData()"><spring:message code="field_delete"/></a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" plain="true" onclick="outputFieldData()"><spring:message code="field_output"/></a>
                <input type="file" id="uploadFile" hidden="hidden" name="uploadFile" onchange=" uploadInput()"/>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-redo" plain="true" onclick="inputFieldData()"><spring:message code="field_input"/></a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-up" plain="true" onclick="upNode()"><spring:message code="field_up"/></a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-down" plain="true" onclick="downNode()"><spring:message code="field_down"/></a>
                <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-tip" plain="true" onclick="setDatabase()"><spring:message code="schema_database_set"/></a>
            </div>
            <thead>
            <tr>
                <th  data-options="field:'text'" width="350" align="left"><spring:message code="field_text"/></th>
                <th  data-options="field:'attributes'" width="200" align="center"><spring:message code="field_attr"/></th>
            </tr>
            </thead>
        </table>
        <div id="databaseData_dialog" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
             closed="true" buttons="#databaseData_save_dialog_buttons" modal="true">
            <div class="ftitle"><spring:message code="input_node_info"/></div>
            <form id="databaseData_form" method="post">
                <div id="database_data_name" class="fitem">
                    <label><spring:message code="node_name"/></label>
                    <input  type="text" name="name" required="required"/>
                </div>
                <div id="database_data_type" class="fitem">
                    <label><spring:message code="node_type"/></label>
                    <select class="easyui-combobox" name="catalogType" id="dataType"
                            data-options="onSelect:selectDatabaseDataType"
                            required="required">
                        <option value="<spring:message code="field_catalog_type"/>" ><spring:message code="field_catalog_name"/></option>
                        <option value="<spring:message code="field_data_float_type"/>" ><spring:message code="field_data_float_name"/></option>
                        <option value="<spring:message code="field_data_text_type"/>" ><spring:message code="field_data_text_name"/></option>
                        <option value="<spring:message code="field_data_picture_type"/>" ><spring:message code="field_data_picture_name"/></option>
                        <option value="<spring:message code="field_data_attach_type"/>" ><spring:message code="field_data_attach_name"/></option>
                        <option value="<spring:message code="field_data_matrix_type"/>" ><spring:message code="field_data_matrix_name"/></option>
                        <option value="<spring:message code="field_data_multi_type"/>" ><spring:message code="field_data_multi_name"/></option>
                        <option value="<spring:message code="field_data_3D_type"/>" ><spring:message code="field_data_3D_name"/></option>
                        <option value="<spring:message code="field_data_link_type"/>" ><spring:message code="field_data_link_name"/></option>
                        <option value="<spring:message code="field_data_time_type"/>" ><spring:message code="field_data_time_name"/></option>
                        <option value="<spring:message code="field_data_video_type"/>" ><spring:message code="field_data_video_name"/></option>                                             
                     <option value="<spring:message code="field_data_3matrix_type"/>" ><spring:message code="field_data_3matrix_name"/></option>
                    </select>
                </div>
                <div id="float_unit" class="fitem" hidden="hidden">
                    <label><spring:message code="field_float_unit"/></label>
                    <input id="float_unit_input" />
                </div>
                <div id="float_trend" class="fitem" hidden="hidden">
                    <label><spring:message code="field_float_trend"/></label>
                    <input name="float_trend_radio" type="radio" value="1" id="trendRadio1"/><label><spring:message code="float_trend_max"/></label>
                    <input name="float_trend_radio" type="radio" value="2" id="trendRadio2"/><label><spring:message code="float_trend_min"/></label>
                </div>
                <div id="matrix_title_div" class="fitem" hidden="hidden">
                    <label><spring:message code="field_matrix_title"/></label>
                    <textarea id="titlearea" rows="4" cols="22"></textarea>
                </div>
                <div id="matrix_tip" class="fitem" >
                    <label></label>
                    <label style="width:220px"><spring:message code="field_matrix_tip"/></label>
                </div>
                 <div id="3matrix_div" class="fitem" hidden="hidden">
                    <div>
                        <label><spring:message code="field_3matrix_x_name"/></label>
                        <input id="3matrix_x_name">
                        <label><spring:message code="field_3matrix_x_title"/></label>
                        <textarea id="title_x" rows="4" cols="21"></textarea>
                        <label></label><label style="width:200px"><spring:message code="field_3matrix_tip"/></label>
                    </div>
                    <div>
                        <label><spring:message code="field_3matrix_y_name"/></label>
                        <input id="3matrix_y_name">
                        <label><spring:message code="field_3matrix_y_title"/></label>
                        <textarea id="title_y" rows="4" cols="21"></textarea>
                        <label></label><label style="width:200px"><spring:message code="field_3matrix_tip"/></label>
                    </div>
                    <div>
                        <label><spring:message code="field_3matrix_z_name"/></label>
                        <input id="3matrix_z_name">
                    </div>
                </div>
            </form>
        </div>
        <div id="databaseData_save_dialog_buttons">
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveFieldData()"><spring:message code="save"/></a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#databaseData_dialog').dialog('close')"><spring:message code="cancel"/></a>
        </div>

    </div>
    <div title=<spring:message code="field_tab2_title"/> data-options="iconCls:'icon-edit'" style="width:100%;height:100px;padding:10px;">
        <table id="authorityTable" style="width:800px;">
            <tr>
                <th>
                    <label><spring:message code="auth_database_read"/></label>
                </th>
                <th><select class="easyui-combobox" id="authDR" data-options="multiple:true, multiline:true" style="width:250px;height:100px">
                </select>
                </th>
                <th>
                    <label><spring:message code="auth_database_write"/></label>
                </th>
                <th><select class="easyui-combobox"  id="authDW" data-options="multiple:true, multiline:true" style="width:250px;height:100px">
                </select>
                </th>
                <th>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveAuth()"><spring:message code="save"/></a>
                </th>
            </tr>
        </table>
    </div>
</div>
<script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/ajaxfileupload.js"></script>
<script type="text/javascript">
    function selectDatabaseDataType(record){
        params()['selectedRecordType'] = record.value;
    }
</script>
<%----%>
<script type="text/javascript">
    function inputFieldData(){
        $("#uploadFile")[0].click();
    }
    function uploadInput(){
        var row = $('#database_data').treegrid('getSelected');
        var fieldId;
        if(row==null){
            fieldId=1;
        }else{
            fieldId=row.id;
        }
        var file=document.getElementById("uploadFile");
        file.click();
        var value=file.value;
        if(value==null){
            $.messager.alert("提示","文件空","info");
        }
        var fileId=[];
        fileId[0]=document.getElementById("uploadFile").id;

        $.ajaxFileUpload({
            url:"<%=request.getContextPath()%>/field/upload?schemaId="+params()['databaseId']+"&fieldId="+fieldId,
            fileElementId:fileId,
            secureuri:false,
            dataType:'json',
            success:function(data,status){
                if(data==200){
                    $("#database_data").treegrid("reload");
                    $.messager.alert("提示","导入成功","info");
                }else{
                    $.messager.alert("错误","导入失败","error");
                }
            },
            error:function(data,status,e){
                $.messager.alert("错误","导入失败","error");
            }
        });
    }
    function saveInfoPicture(){
        $("#uploadPicture")[0].click();
    }
    function uploadInfoPicture(){
        var fileId=[];
        fileId[0]=document.getElementById("uploadPicture").id;
        var pos=$("#uploadPicture").val().lastIndexOf("\\");
        var picName=$("#uploadPicture").val().substring(pos+1);
        $.ajaxFileUpload({
            url:schemaUrl.savePicture+"?schemaId="+params()['databaseId'],
            fileElementId:fileId,
            secureuri:false,
            dataType:'json',
            success:function(data,status){
                if(data==200){
                    $.messager.alert("提示","导入成功","info");
                    $("#infoPicName").prop('value',picName);
                }else{
                    $.messager.alert("错误","导入失败","error");
                }
            },
            error:function(data,status,e){
                $.messager.alert("错误","导入失败","error");
            }
        });
    }
</script>
</body>
</html>
